home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / GAPLib.lha / GAPLib / include / GAP.h < prev   
Encoding:
C/C++ Source or Header  |  1999-04-27  |  4.8 KB  |  145 lines

  1. /*
  2.  * GAP-Lib (C)1998-1999 Peter Bengtsson
  3.  * The Genetic Algorithm Programming Library.
  4.  *
  5.  */
  6.  
  7. #ifndef    __GAP_H__
  8. #define    __GAP_H__
  9.  
  10. #ifdef    __STDC_VERSION__
  11. #if    __STDC_VERSION__==199901L
  12. #include <inttypes.h>
  13. typedef intptr_t IPTR
  14. #define    __IPTR_DONE
  15. #endif
  16. #endif
  17.  
  18. #ifndef    TAG_DONE    /* This should be defined if tags are already defined. */
  19.  
  20. typedef    long    Tag;
  21. #ifndef    __IPTR_DONE
  22. typedef    unsigned long IPTR;
  23. #endif
  24.  
  25. struct TagItem    {
  26.     Tag    ti_Tag;
  27.     IPTR    ti_Data;
  28. };
  29.  
  30. #define    TAG_DONE        (0L)
  31. #define  TAG_END     TAG_DONE
  32. #define    TAG_IGNORE    (1L)
  33. #define    TAG_MORE        (2L)
  34.  
  35. #endif
  36.  
  37. #ifndef    TAG_DUMMY
  38. #define    TAG_DUMMY    (64L)
  39. #endif
  40.  
  41. #ifndef    TRUE
  42. #define    TRUE    (~0)
  43. #define    FALSE    (0)
  44. #endif
  45.  
  46. #define    GAP_RAND_MAX    0x7ffffffd
  47.  
  48. /* Tags for CreatePopulation.
  49.  *
  50.  */
  51.  
  52. #define    POP_Init            (TAG_DUMMY+0x01)    /* Initialization function. */
  53. #define    POP_Destruct    (TAG_DUMMY+0x02)    /* Destructor function. */
  54. #define    POP_Cache        (TAG_DUMMY+0x03)    /* Cache? Defaults to TRUE. */
  55.  
  56. /* Tags for Evolve(). These define different parameters of the evolution
  57.  * of the Polyphant population.
  58.  */
  59.  
  60. #define    EVL_Evaluator     (TAG_DUMMY+0x01)    /* Fitness function, _REQUIRED_ */
  61. #define    EVL_Mutator         (TAG_DUMMY+0x02)    /* Mutator function */
  62. #define    EVL_Crosser         (TAG_DUMMY+0x03)    /* Crossover function */
  63. #define    EVL_Elite         (TAG_DUMMY+0x04)    /* No. of Elite individuals to copy without modification */
  64. #define    EVL_Dump             (TAG_DUMMY+0x05)    /* Dump the worst individuals */
  65. #define    EVL_Select         (TAG_DUMMY+0x06)    /* Select type */
  66. #define    EVL_Stats         (TAG_DUMMY+0x07)    /* Generate statistics  (Defaults to TRUE) */
  67. #define    EVL_PreMutate     (TAG_DUMMY+0x08)    /* Mutate before generating new individuals (Defaults to FALSE) */
  68. #define    EVL_Newbies         (TAG_DUMMY+0x09)    /* No. of new individuals to generate. */
  69. #define    EVL_Flags         (TAG_DUMMY+0x0A)    /* Mode of operation Flags */
  70. #define    EVL_Mensurator     (TAG_DUMMY+0x0B)    /* Measures the distance 'twixt individuals */
  71. #define    EVL_Crowding     (TAG_DUMMY+0x0C)    /* Use crowding replacement */
  72. #define    EVL_InitDumped     (TAG_DUMMY+0x0D)    /* If EVL_Dump>0, re-initialize dumped individuals. */
  73. #define    EVL_EraseBest     (TAG_DUMMY+0x0E)    /* If EVL_Newbies>0, replace the best individuals. */
  74. #define    EVL_Transcriber (TAG_DUMMY+0x0F)    /* Transcription function. */
  75. #define    EVL_Thermostat     (TAG_DUMMY+0x10)    /* Regulates selection 'temperature'. */
  76.  
  77. /* For EVL_Select */
  78.  
  79. #define    DRANDOM        1L        /* Double Random */
  80. #define    FITPROP        2L        /* Fitness Proportionate */
  81. #define    SIGMA            3L        /* Sigma Scaled Selection */
  82. #define    TOURNAMENT    4L        /* Tournament Selection */
  83. #define    INORDER        5L        /* Sorted in order of fitness */
  84. #define    TEMPERATURE    6L        /* Temperature-dependant selection eg. Boltzmann */
  85. #define    UNIVERSAL    7L        /* Stochastic Universal selection */
  86.  
  87. /* For POP_Init */
  88.  
  89. #define    ZERO_INIT    0L        /* Zeroed bits */
  90. #define    RAND_INIT    1L        /* Random bits */
  91.  
  92. /* For EVL_Flags */
  93.  
  94. #define    FLG_InitDumped            (1L<<0)
  95. #define    FLG_EraseBest            (1L<<1)
  96. #define    FLG_Crowding            (1L<<2)
  97. #define    FLG_Statistics            (1L<<3)
  98.  
  99. #define    UnitedKingdomFlag    (1L<<31)
  100.  
  101. /* Structures */
  102.  
  103. struct Popstat {
  104.     double    AverageFitness;        /* Average fitness of population. */
  105.     double    MedianFitness;            /* Median fitness of the population. */
  106.     double    TypeFitness;            /* Type fitness value (Most common) */
  107.     long        TypeCount;                /* Countvalue for type fitness */
  108.     double    StdDeviation;            /* Standard deviation */
  109.     double    MaxFitness;                /* Fitness of the fittest individual.  */
  110.     double    MinFitness;                /* Fitness of the least fit individual. */
  111.     void        *Max;                        /* Pointer to the fittest individual. */
  112.     long        Generation;
  113. };
  114.  
  115. struct Population {
  116.     long     NumPolys;
  117.     long     Generation;
  118.     long     Flags;
  119.     struct Popstat Stat;
  120.     long     Bytes;
  121.     void    *Polys;
  122.     void    *Magic;
  123. };
  124.  
  125. extern int                         EnterGAP(int);
  126. extern void                      Crossover(void *Ind1,void *Ind2,const long int At,const long int Size);
  127. extern void                      Flip(void *Individual,const long int At);
  128. extern int                           Testbit(void *Individual,long int At);
  129. extern void                         InitRand(const long int);
  130. extern unsigned long int     Rnd(const long int Max);
  131. extern double                     InRand(const double From,const double To);
  132. extern double                     GaussRand(const double My,const double Sigma);
  133. extern double                     PoissonRand(const double My);
  134. extern int                         TossRand(const double P);
  135. extern struct Population    *CreatePopulation(const long int NumIndividuals,const long int Size,struct TagItem *);
  136. extern struct Population    *CreatePopulationT(const long int NumIndividuals,const long int Size,...);
  137. extern struct Population    *Evolve(struct Population *OldPop,struct TagItem *);
  138. extern struct Population    *EvolveT(struct Population *,...); /* Varargs interface to Evolve() */
  139. extern void                         DeletePopulation(struct Population *Pop);
  140. extern void                        *PopMember(struct Population *,const long int);
  141. extern double                     IRange(const unsigned long int,const double,const double);
  142. extern unsigned long int     HammingDist(void *,void *,const int);
  143.  
  144. #endif
  145.